/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('appstream-center', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ExpireLoginTokenRequest {
  endUserId?: string(name='EndUserId', example='testuser'),
  loginToken?: string(name='LoginToken', example='v185fdd7f6d39fa7861981639366085772e150a390a5bb7b43c4e62440d94fc392b945770e1596cebe90085ce0af4d****'),
  officeSiteId?: string(name='OfficeSiteId', example='cn-beijing+dir-172301****'),
  sessionId?: string(name='SessionId', example='a863f4c3-2f1d-4971-8cf7-e2b92ae9****'),
}

model ExpireLoginTokenResponseBody = {
  requestId?: string(name='RequestId', example='1CBAFFAB-B697-4049-A9B1-67E1FC5F****'),
}

model ExpireLoginTokenResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ExpireLoginTokenResponseBody(name='body'),
}

async function expireLoginTokenWithOptions(request: ExpireLoginTokenRequest, runtime: Util.RuntimeOptions): ExpireLoginTokenResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.endUserId)) {
    body['EndUserId'] = request.endUserId;
  }
  if (!Util.isUnset(request.loginToken)) {
    body['LoginToken'] = request.loginToken;
  }
  if (!Util.isUnset(request.officeSiteId)) {
    body['OfficeSiteId'] = request.officeSiteId;
  }
  if (!Util.isUnset(request.sessionId)) {
    body['SessionId'] = request.sessionId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ExpireLoginToken',
    version = '2021-02-18',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function expireLoginToken(request: ExpireLoginTokenRequest): ExpireLoginTokenResponse {
  var runtime = new Util.RuntimeOptions{};
  return expireLoginTokenWithOptions(request, runtime);
}

model GetAuthCodeRequest {
  autoCreateUser?: boolean(name='AutoCreateUser'),
  endUserId?: string(name='EndUserId', example='alice'),
  externalUserId?: string(name='ExternalUserId', example='alice'),
  policy?: string(name='Policy', example='{
      "Version": "1",
      "Resource": {
            "Type": "AppInstanceGroup",
            "Id": "aig-9ciijz60n4xsv****"
      }
}'),
}

model GetAuthCodeResponseBody = {
  authModel?: {
    authCode?: string(name='AuthCode', example='acv2ZEq2TNSqOlX+DvyetHGRT08iPhbWg/os1W4HojpBxkMQZkAnbKSfz/wNvS0E149IQZ5TogvBUE8ghCSVV+QBnv48Y+sn4z9fY5ywZA1peI5s4TplQI0TADBhPZXEIzMOdmbNsDGGlGcKOAq8ixd1Epzdu9XfvRzdLOO6o3zQwTZxXsjOgGBW8JTcgCP9W9iYiIjHIdZ2VCAnmMzuyVkyED8gymEevH10QoclyH/O3s8Yq6VF34gMXihDQeiI8PyiAZrW0JWXSWpdy3n4yGtAqMAgv46FzTA+XJ6C********'),
    endUserId?: string(name='EndUserId', example='alice'),
    expireTime?: string(name='ExpireTime', example='2015-01-23T12:33:18Z'),
  }(name='AuthModel'),
  requestId?: string(name='RequestId', example='1CBAFFAB-B697-4049-A9B1-67E1FC5F****'),
}

model GetAuthCodeResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetAuthCodeResponseBody(name='body'),
}

async function getAuthCodeWithOptions(request: GetAuthCodeRequest, runtime: Util.RuntimeOptions): GetAuthCodeResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.autoCreateUser)) {
    body['AutoCreateUser'] = request.autoCreateUser;
  }
  if (!Util.isUnset(request.endUserId)) {
    body['EndUserId'] = request.endUserId;
  }
  if (!Util.isUnset(request.externalUserId)) {
    body['ExternalUserId'] = request.externalUserId;
  }
  if (!Util.isUnset(request.policy)) {
    body['Policy'] = request.policy;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetAuthCode',
    version = '2021-02-18',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getAuthCode(request: GetAuthCodeRequest): GetAuthCodeResponse {
  var runtime = new Util.RuntimeOptions{};
  return getAuthCodeWithOptions(request, runtime);
}

